package p1100;

import java.time.format.DateTimeFormatter;
import java.util.Calendar;

/**
 * @author pengjz <br>
 * @version 1.0 <br>
 * @description Leetcode_1154 <br>
 * @date 2021/12/21 11:34 <br>
 */
public class Leetcode_1154 {


    public static final int[] monthDays = new int[]{31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public int dayOfYear(String date) {
        String[] a = date.split("-");
        int year = Integer.parseInt(a[0]);
        int month = Integer.parseInt(a[1]);
        int day = Integer.parseInt(a[2]);
        if (month == 1) {
            return day;
        } else if (month == 2) {
            return 31 + day;
        } else {
            for (int i = 0; i < month - 3; i++) {
                day += monthDays[i];
            }
            if (isLeapYear(year)) {
                return 29 + 31 + day;
            } else {
                return 28 + 31 + day;
            }
        }
    }

    private boolean isLeapYear(int year) {
        return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
    }

    public static void main(String[] args) {
        Leetcode_1154 leetcode = new Leetcode_1154();
        System.out.println(leetcode.dayOfYear("2021-01-11"));
        System.out.println(leetcode.dayOfYear("2021-02-11"));
        System.out.println(leetcode.dayOfYear("2021-03-11"));
        System.out.println(leetcode.dayOfYear("2021-04-11"));
    }
}
